﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Routing;

namespace Infrastructure.Web.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:RouteHyperLink runat=server></{0}:RouteHyperLink>")]
    public class RouteHyperLink : WebControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string NavigateRoute
        {
            get
            {
                String s = (String)ViewState["NavigateRoute"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["NavigateRoute"] = value;
            }
        }
        protected override void RenderContents(HtmlTextWriter output)
        {
            var vp = RouteTable.Routes.GetVirtualPath(null, NavigateRoute, null).VirtualPath;
            output.Write(vp);
        }
    }
}
